<form action="{:sysuri()}" method="post" data-auto="true" class="layui-form layui-card" data-table-id="EmployInfo">
    <div class="layui-card-body padding-left-40 layui-col-space10">

        <div class="layui-col-md12">
            <label class="layui-form-label">{:Lang("标题")}:</label>
            <div class="layui-input-block">

                <input name="title" value='{$vo.title|default=""}' required class="layui-input ">
            </div>
        </div>

        {if $vo.level == 2 && $vo.type == 2}
        <div class="layui-col-md12 file_path" {if 1 == $vo.type} style="display: none" {/if}>
            <label class="layui-form-label"></label>
            <div class="layui-input-block">
                <div style="display: flex;">
                    <a id="upload_button" class="layui-btn layui-bg-blue" >上传执行文件</a>
                    <input type="text" name="file_path" readonly class="layui-input "  value="{$vo.file_path}">
                    <input type="file" style="display: none;" name="file_upload" id="file_upload" >
                </div>

            </div>
        </div>
        <div class="layui-col-md12">
            <label class="layui-form-label">{:Lang("分数（两位）")}:</label>
            <div class="layui-input-block">

                <input name="gold" value='{$vo.gold|default=""}' placeholder="请输入分数" pattern="^[1-9][0-9]{0,1}$"  vali-name="分数"  required class="layui-input ">
            </div>
        </div>
        {/if}


        <div class="layui-col-md12">
            <label class="layui-form-label">{:Lang("排序")}:</label>
            <div class="layui-input-block">

                <input name="sort" value='{$vo.sort|default=1}' placeholder="请输入排序" pattern="^[1-9][0-9]{0,1}$"  vali-name="排序"  required class="layui-input ">
            </div>
        </div>



        <div class="layui-form-item">
            <label class="layui-form-label">{:Lang("实战详细描述")}:</label>
            <div class="layui-input-block" >
                <textarea name="content" placeholder="请输入实战详细描述" lay-verify="" class="layui-textarea" style="height: 350px;">{$vo.content|default=""}</textarea>
                <p class="help-block"></p>
            </div>
        </div>
    </div>

    <div class="hr-line-dashed"></div>
    {notempty name='vo.id'}<input type='hidden' value='{$vo.id}' name='id'>{/notempty}

    <div class="layui-form-item text-center">
        <button class="layui-btn" type='submit'>保存数据</button>
        <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗？" data-close>取消编辑</button>
    </div>
</form>

<script>

    $(function () {
        // 异步加载富文本编辑器
        require(['ckeditor'], function () {
            setTimeout(function () {
                // 初始化富文本编辑器
                window.createEditor('[name=content]', {height: 350});
            },500)
        });

        // 绑定点击事件处理器
        $("#upload_button").click(function() {

            console.log(123)
            $("#file_upload").trigger("click");
            // 使用示例
        });


        $("#file_upload").change(function () {
            const file = document.getElementById('file_upload').files[0];

            let formData = new FormData();
            formData.append('file', file);
            formData.append('fileName', file.name);

            fetch("{:sysuri('upload')}", {
                method: 'POST',
                body: formData
            }).then(response => {
                if (response.ok) {
                    return response.json(); // 转换为JSON
                }
            }).then(data => {

                $('input[name=file_path]').val(data.data);

            })
        })
    });

</script>